package com.wqc.web;

import com.wqc.common.util.DictUtils;
import com.wqc.model.Dictionary;
import com.wqc.service.DictionaryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dict")
public class DictionaryController {

    private static final Logger LOGGER = LoggerFactory.getLogger(DictionaryController.class);

    @Autowired
    private DictionaryService dictionaryService;

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/list")
    public List<Dictionary> getDictList() {
       return dictionaryService.getAllDictionary();
    }

    @GetMapping("/getOne")
    public Dictionary getOne() {
        String typeAndKey = "GroupType@E";
        return dictionaryService.getDictionaryByTypeAndKey(typeAndKey);
    }

    @GetMapping("/get")
    public Dictionary getDictByCondition(String key) {

        Dictionary dict = (Dictionary) DictUtils.setPopType(key);

        //Dictionary dict = (Dictionary) redisTemplate.opsForSet().pop(CommonConstants.DICT_TYPE+key+":"+"zh-CN");//get(CommonConstants.DICT_TYPE+key+"zh-CN");

        /*Set keys = redisTemplate.opsForHash().keys(CommonConstants.DICT_TYPEANDKEY+key);
        for (Object o : keys) {
            Object o1 = redisTemplate.opsForHash().get(CommonConstants.DICT_TYPEANDKEY + key, o);
            System.out.println(o1.toString());
        }*/
        return dict;
    }

}
